<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>注册页</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../frame/static/css/style.css">
    <link rel="icon" href="../frame/static/image/code.png">
</head>
<body>

<div class="login-main">
    <header class="layui-elip">注册页</header>
    <form class="layui-form">
        <div class="layui-input-inline">
            <input type="text" id="wcode" lay-verify="required" placeholder="微信号(非微信昵称，必填项)" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input id="passwd" type="password" placeholder="密码(必填项)" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="phone" lay-verify="required" placeholder="电话号码(可以不填写)" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="chname" placeholder="邀请人(可以不填写)" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline login-btn">
            <button onclick="regiser()" class="layui-btn">注册</button>
        </div>
        <hr/>
        <p><a href="/common/ulogin" class="fl">已有账号？立即登录</a><a href="javascript:;" class="fr">忘记密码？</a></p>
    </form>
</div>


<script src="../frame/layui/layui.js"></script>
<script src="/lib/jquery-1.11.3.min.js"></script>
<script src="/lib/jquery.cookie.js"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form
            , $ = layui.jquery;
    });


    function regiser() {
        if ($("#wcode").val() != "" && $("#passwd").val() != "") {
            var params = {
                "wcode": $("#wcode").val(),
                "passwd": $("#passwd").val(),
                "chname": $("#chname").val(),
                "phone": $("#phone").val()
            };
            $.ajax({
                type: "POST",
                dataType: "json",
                data: JSON.stringify(params),
                contentType: "application/json",
                url: "/user/sign",
                success: function (result) {
                    console.log(result);
                    if (result.code == "200") {
                        var cookietime = new Date();
                        cookietime.setTime(cookietime.getTime() + (60 * 60 * 1000));//coockie保存一小时
                        $.cookie("cuname", result.data.wcode, {expires: cookietime});
                        $.cookie("cid", result.data.pkguid, {expires: cookietime});
                        localStorage.setItem('cid', result.data.pkguid);
                        localStorage.setItem('cuname', result.data.wcode);
                        window.location.href = "/common/ulogin";  //注册成功跳转到登录页面
                    } else if (result.code == "201") {
                        alert(result.message);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var resultJson = eval('(' + XMLHttpRequest.responseText + ')');
                }
            });
        } else {
            alert('用户名或密码为空！')
        }
    }
</script>
</body>
</html>